package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrapp.base.service.MOmsDualHighIndicatorRelationshipService;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsDualHighIndicatorRelationshipMapper;
import com.wicket.okrapp.dal.po.mbg.OmsDualHighIndicatorRelationship;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author  CHS
 * @since 2025-10-02
 *
 *
 * @version 1.0
 */
@Service
public class MOmsDualHighIndicatorRelationshipServiceImpl
        extends ServiceImpl<OmsDualHighIndicatorRelationshipMapper, OmsDualHighIndicatorRelationship>
        implements MOmsDualHighIndicatorRelationshipService {

    @Autowired
    OmsDualHighIndicatorRelationshipMapper OmsDualHighIndicatorRelationshipMapper;

    /**
     * 查双高标准框架数据列表[2536]
     * gen by moon at 10/15/2022, 9:58:55 PM
     */
    @Trace(operationName = "查双高标准框架数据列表")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
    @Override
    @Transactional(rollbackFor=Exception.class)
    public  List<OmsDualHighIndicatorRelationship>  queryDualHighTaskRelationshipList(OmsDualHighIndicatorRelationship obj) {

        try {
            QueryWrapper<OmsDualHighIndicatorRelationship> queryWrapper = new QueryWrapper<>();
            obj.setIsValid("FALSE");
            obj.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID

            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(obj);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsDualHighIndicatorRelationship.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsDualHighIndicatorRelationship.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsDualHighIndicatorRelationship.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsDualHighIndicatorRelationship>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
    }

    /**
     * 查双高标准框架数据详情[2515]
     * gen by moon at 4/24/2023, 12:54:06 AM
     */
    @Trace(operationName = "查双高标准框架数据详情")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
    @Override
    @Transactional(rollbackFor=Exception.class)
    public  OmsDualHighIndicatorRelationship  queryDualHighTaskRelationshipDetail(OmsDualHighIndicatorRelationship obj) {

        try {
            obj.setIsValid("FALSE");
            obj.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            obj.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            QueryWrapper<OmsDualHighIndicatorRelationship> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(obj);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsDualHighIndicatorRelationship> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsDualHighIndicatorRelationship retData = retList.get(0);

                return retData;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
    }

    /**
     * 新增双高标准框架数据[2346]
     * gen by moon at 10/15/2022, 9:58:53 PM
     */
    @Trace(operationName = "新增双高标准框架数据")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
    @Override
    @Transactional(rollbackFor=Exception.class)
    public  String  addDualHighTaskRelationship(OmsDualHighIndicatorRelationship OmsDualHighIndicatorRelationship) {
        OmsDualHighIndicatorRelationship.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        OmsDualHighIndicatorRelationship.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        OmsDualHighIndicatorRelationship.setIsValid("FALSE");
        OmsDualHighIndicatorRelationship.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
        OmsDualHighIndicatorRelationship.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
        if(super.save(OmsDualHighIndicatorRelationship)){
            return OmsDualHighIndicatorRelationship.getDualHighId();
        }else {
            return "-1";
        }

    }

    /**
     * 修改双高标准框架数据[2917]
     * gen by moon at 10/15/2022, 9:58:56 PM
     */
    @Trace(operationName = "修改双高标准框架数据")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
    @Override
    @Transactional(rollbackFor=Exception.class)
    public  boolean  updateDualHighTaskRelationship(OmsDualHighIndicatorRelationship OmsDualHighIndicatorRelationship) {
        OmsDualHighIndicatorRelationship.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        return super.updateById(OmsDualHighIndicatorRelationship);
    }

    /**
     * 删除双高标准框架数据[4092]
     * gen by moon at 10/15/2022, 9:58:58 PM
     */
    @Trace(operationName = "删除双高标准框架数据")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
    @Override
    @Transactional(rollbackFor=Exception.class)
    public  boolean  deleteDualHighTaskRelationship(String planningId ) {

        return super.removeById(planningId);
    }
}
